Little changes on Colombian Programming Contest solutions.
[and.git] / 299 - Train swapping / 299.cpp
blob96b7d9e0f17d36f9a74bfd5d47cc1daf9e698eb3
1 #include <algorithm>
2 #include <stdio.h>
3 int tren[50], c, l, i, j, r;
5 int bubblesort(){
6 for (r=0, i=1; i<l; i++)
7 for (j=0; j<l-1; j++)
8 if (tren[j] > tren[j+1]){
9 std::swap(tren[j], tren[j+1]);
10 r++;
12 return r;
15 int main(){
16 for (scanf("%d", &c); c--; printf("Optimal train swapping takes %d swaps.\n", bubblesort())){
17 for (scanf("%d", &l), i = 0; i<l; scanf("%d", &tren[i++]));
19 return 0;